//
//  LGTeamApproveController.m
//  BreathTrainingTool
//
//  Created by 1234 on 2024/7/12.
//  审批列表

#import "LGTeamApproveController.h"
#import "LGTeamApproveCell.h"
@interface LGTeamApproveController ()<UITableViewDelegate,UITableViewDataSource,LGTeamApproveCellDelegate>
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)NSArray *dataArray;



@end

@implementation LGTeamApproveController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"通知";
    [self.view addSubview:self.tableView];
    [self emptyViewWithSuperView:self.tableView frame:self.tableView.bounds];
    [self requestData];
}


-(void)requestData{
    [RequestUtil withGET:@"/team/toBeApprove" parameters:@{@"doctorId":kUserId} header:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if (code == 200) {
            self.dataArray = returnData;
            [self.tableView reloadData];
        }
        if (self.dataArray.count == 0) {
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无通知" offset:-50];
        }
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if (self.dataArray.count == 0) {
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无通知" offset:-50];
        }
    }];
}

-(void)agreeTeamApprove:(NSString *)apporoveid{
    [RequestUtil bodayPOST:@"/team/statusApprove" parameters:@{@"id":apporoveid,@"status":@"1"} header:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            [self requestData];
        }else{
            [TooltipView showMessage:message offset:0];
        }
    } error:^(NSError *error) {
        [TooltipView showMessage:@"审批失败，请重试" offset:0];
    }];
}

-(void)refuseTeamApprove:(NSString *)apporoveid{
    [RequestUtil bodayPOST:@"/team/statusApprove" parameters:@{@"id":apporoveid,@"status":@"2"} header:YES success:^(NSInteger code, NSString *message, id returnData) {
        if (code == 200) {
            [self requestData];
        }else{
            [TooltipView showMessage:message offset:0];
        }
    } error:^(NSError *error) {
        [TooltipView showMessage:@"审批失败，请重试" offset:0];
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGTeamApproveCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dataDic = self.dataArray[indexPath.row];
    cell.delegate = self;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    return headView;
}
-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGTeamApproveCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor colorWithString:@"#F8F8F8"];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(8))];
    }
    return _tableView;
}


@end
